#!/bin/sh
cwDir=`pwd`
cd `dirname $0`
if [ "x$1" = "x-h" ] || [ "x$1" = "x--help" ]; then
  echo "usage: $0 [ dest [ moduleName ] ]"
  exit 1
fi
if [ "x$1" = "x" ]; then
  echo "Veuillez Choisir le repertoire de destination:"
  read dest
  echo
else
  dest="$1"
fi
dest="$cwDir/$dest"
if [ ! -d "$dest" ]; then
  echo "Not a directory"
  exit 1
fi
shift

if [ "x$1" = "x" ]; then
  echo "Veuillez Choisir le nom de votre module"
  read tmp
  echo
else
  tmp="$1"
fi

moduleName=`echo $tmp | sed 's/[^a-zA-Z0-9]/_/g'`
repPattern="s!<#MonModule#>!$moduleName!g;s!<#MONMODULE#>!`echo $moduleName | tr 'a-z' 'A-Z'`!g;"

echo "moduleName: $moduleName"
echo

echo "create $dest/$moduleName.cpp"
sed "$repPattern" < "template.cpp" > "$dest/$moduleName.cpp"

echo "create $dest/$moduleName.h"
sed "$repPattern" < "template.h" > "$dest/$moduleName.h"

echo "finished"